<?php
class IndexAction extends globalAction{
    private $innDao;
    
	public function _initialize() {
		parent::_initialize();
        $this->innDao = D('Inn');
	}
    
	function index() {
        
        /***********************************************************************
         * 特卖客栈
         **********************************************************************/
        $condition = array();//查询条件
        $condition[$this->innDao->_map['menuId']] = 585;//客栈数据标志
        $condition[$this->innDao->_map['status']] = 1212;//审核标志
        $order = array();
        $order[$this->innDao->_map['display_order']] = 'asc';
        
        $innSpecialList = $this->innDao->unionField()
            ->where($condition)
            ->limit(5)
            ->order($order)
            ->select();
		$this->assign("innSpecialList",$innSpecialList);

		/***********************************************************************
         * 客栈排行榜
         **********************************************************************/
        $condition = array();//查询条件
        $condition[$this->innDao->_map['menuId']] = 585;//客栈数据标志
        $condition[$this->innDao->_map['status']] = 1212;//审核标志
        $order = array();
        $order[$this->innDao->_map['display_order']] = 'desc';
        
        $innTopList = $this->innDao->unionField()
            ->where($condition)
            ->limit(5)
            ->order($order)
            ->select();
		$this->assign("innTopList",$innTopList);
		
		/***********************************************************************
         * 最新加入客栈
         **********************************************************************/
        $condition = array();//查询条件
        $condition[$this->innDao->_map['menuId']] = 585;//客栈数据标志
        $condition[$this->innDao->_map['status']] = 1212;//审核标志
        $order = array();
        $order[$this->innDao->_map['addTime']] = 'desc';
        
        $innNewList = $this->innDao->unionField()
            ->where($condition)
            ->limit(8)
            ->order($order)
            ->select();
		$this->assign("innNewList",$innNewList);
        
        /***********************************************************************
         * 热门客栈
         **********************************************************************/
        $condition = array();//查询条件
        $condition[$this->innDao->_map['menuId']] = 585;//客栈数据标志
        $condition[$this->innDao->_map['status']] = 1212;//审核标志
        $order = array();
        $order[$this->innDao->_map['hot']] = 'desc';
        
        $innHotList = $this->innDao->unionField()
            ->where($condition)
            ->limit(8)
            ->order($order)
            ->select();
		$this->assign("innHotList",$innHotList);
        
        /***********************************************************************
         * 推荐客栈
         **********************************************************************/
        $condition = array();//查询条件
        $condition[$this->innDao->_map['menuId']] = 585;//客栈数据标志
        $condition[$this->innDao->_map['status']] = 1212;//审核标志
        $order = array();
        $order[$this->innDao->_map['hot']] = 'desc';
        
        $innRecommendList = $this->innDao->unionField()
            ->where($condition)
            ->limit(8)
            ->order($order)
            ->select();
		$this->assign("innRecommendList",$innRecommendList);
        
        /***********************************************************************
         * 热门城市
         **********************************************************************/
        //获取热门客栈所在城市
        $field = array();
        $field[$this->innDao->_map['area']] = 'city';
        $condition = array();//查询条件
        $condition[$this->innDao->_map['menuId']] = 585;//客栈数据标志
        $condition[$this->innDao->_map['status']] = 1212;//审核标志
        $order = array();
        $order[$this->innDao->_map['hot']] = 'desc';
        
        $citys_id = $this->innDao
            ->Distinct(true)
            ->field($field)
            ->where($condition)
            ->limit(15)
            ->order($order)
            ->select();
        //将city_id压入数组
        $citys_id_range = array();
        foreach($citys_id as $city_id) {
            $citys_id_range[] = $city_id['city'];
        }
        //获取城市详情
        $areaDao = D('InnArea');
        $cityHotList = $areaDao
            ->field($areaDao->_map_flip)
            ->where(array(
                $areaDao->_map['id'] => array('in', $citys_id_range)
            ))
            ->select();

        $this->assign("cityHotList",$cityHotList);
        
        /***********************************************************************
         * 客栈搜索框处理
         **********************************************************************/
        //城市列表
        $innAreaDao = D('InnArea');
        $innCity = S('innCity');
        if(empty($innCity)) {
            $innCity = $innAreaDao
                ->field($innAreaDao->_map_flip)
                ->where(array(
                    $innAreaDao->_map['menuId']=>590,
                    $innAreaDao->_map['mainCity']=>1212
                ))
                ->order($innAreaDao->_map['order'])
                ->select();
            S('innCity', $innCity);
        }
        $this->assign('innCity', $innCity);
        
        //客栈类型列表
		$innTypeDao = D('InnType');
        $innTypeList = $innTypeDao
            ->field($innTypeDao->_map_flip)
            ->where(array(
                $innTypeDao->_map['menuId']=>606,
                $innTypeDao->_map['parent']=>0
            ))
            ->select();
        $this->assign('innTypeList', $innTypeList);
        
        /***********************************************************************
         * 取相相关统计数据
         **********************************************************************/
        //初始化统计数据
        if(!($innStat = S('innStat'))) {
            $innStat["checkin"] = rand(100,999);
            $innStat["inncount"] = $this->innDao->where(array($this->innDao->_map['status']=>1212))->count();
            $innStat["vister"] = rand(100,999);
            $innStat["subject"] = rand(100,999);
            $innStat["order"] = rand(100,999);
            $innStat["time"] = time();
            S('innStat', $innStat);
        }
        //定期更新统计数据
        if($innStat["time"] < time() - 5*60) {
            $innStat["checkin"] += rand(0,3);
            $innStat["inncount"] = $this->innDao->where(array($this->innDao->_map['status']=>1212))->count();
            $innStat["vister"] += rand(-50,50);
            $innStat["subject"] += rand(0,3);
            $innStat["order"] += rand(0,3);
            $innStat["time"] = time();
            S('innStat', $innStat);
        }
        $this->assign('innStat', $innStat);
		
		$this->display();
	}
	
}


?>